package com.ssyc.gsk_teacher.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ssyc.common.glide.ImageUtil;
import com.ssyc.common.utils.ScreenUtils;
import com.ssyc.common.utils.UiUtils;
import com.ssyc.gsk_teacher.R;
import com.ssyc.gsk_teacher.activity.TeacherShowVideoWebActivity;
import com.ssyc.gsk_teacher.bean.TeacherShowInfo;

import java.util.List;

/**
 * 教师风采列表适配器
 * Created by Administrator on 2018/6/19 0019.
 */

public class TeacherShowAdapter extends BaseQuickAdapter<TeacherShowInfo.ListBean, BaseViewHolder> {
    private Context context;

    private RelativeLayout.LayoutParams lp;
    private LinearLayout.LayoutParams lpOut;

    public TeacherShowAdapter(Context context, int layoutResId, @Nullable List<TeacherShowInfo.ListBean> data) {
        super(layoutResId, data);
        this.context = context;
        int width = ScreenUtils.getScreenWidth(context) * 16 / 37;
        int height = width ;
        lp = new RelativeLayout.LayoutParams(width, height);
        int outWidth = (ScreenUtils.getScreenWidth(context) - UiUtils.dp2px(10 + 10)) / 2;
        int outHeight = outWidth;
        lpOut = new LinearLayout.LayoutParams(outWidth, outHeight);
    }

    @Override
    protected void convert(BaseViewHolder helper, TeacherShowInfo.ListBean item) {
        RelativeLayout rlOut = helper.getView(R.id.rl_out);
        rlOut.setLayoutParams(lpOut);
        //条目外层布局
        LinearLayout llOut = helper.getView(R.id.ll_out);
        lp.addRule(RelativeLayout.CENTER_IN_PARENT);
        llOut.setLayoutParams(lp);


        ImageView iv_vidio_img = helper.getView(R.id.iv_vidio_img);
        TextView tv_title = helper.getView(R.id.tv_title);
        TextView tv_name = helper.getView(R.id.tv_name);
        TextView tv_time = helper.getView(R.id.tv_time);

        //视频图
        ImageUtil.displayImage(context,iv_vidio_img,item.getPictureUrl(),R.drawable.teacher_show_vidio_default);
        //标题
        tv_title.setText(item.getTitle());
        //上传人
        tv_name.setText(item.getName());
        //创建时间
        tv_time.setText(item.getCreateTime());

        rlOut.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context,TeacherShowVideoWebActivity.class);
                intent.putExtra("url",item.getUrl());
                intent.putExtra("rowid",item.getRowId());
                intent.putExtra("title",item.getTitle());
                context.startActivity(intent);
            }
        });
    }
}
